<<xAct`xTras`

$PrePrint=ScreenDollarIndices;
DefManifold[M, dim, IndexRange[a,h]]
DefMetric[-1, metric[-a,-b],CD,{";","∇"},PrintAs->"g"]

Einstein-Hilbert action

L=RicciScalarCD[]

VarL[metric[a,b]][L]

quadratic gravity

DefConstantSymbol[α]
DefConstantSymbol[β]
DefConstantSymbol[γ]
DefConstantSymbol[Λ]
DefConstantSymbol[Λ0]
DefConstantSymbol[κ]

L=1/κ(RicciScalarCD[]-2 Λ0)+α RicciScalarCD[]^2+β RicciCD[-a,-b]RicciCD[a,b]+γ(RiemannCD[-c,-d,-e,-f]RiemannCD[c,d,e,f]-4RicciCD[-c,-d]RicciCD[c,d]+RicciScalarCD[]^2)

VarL[metric[a,b]][L]

%//FullSimplification[]

%//CollectConstants

Einstein-Maxwell-dilaton theory

DefTensor[phi[],M,PrintAs->"ϕ"]
DefTensor[A[-a],M]
DefTensor[F[-a,-b],M,Antisymmetric[{-a,-b}]]

L=RicciScalarCD[]-(1/2) CD[-a][phi[]]CD[a][phi[]]-(1/4)Exp[-2γ phi[]]F[-a,-b]F[a,b]

field equations for gravity

VarL[metric[a,b]][L]//ContractMetric

field equations for dilaton

VarD[phi[],CD][L]//ToCanonical

field equations for Maxwell field

L/.F[a_,b_]->CD[a][A[b]]-CD[b][A[a]]

VarD[A[-a],CD][%]

temp=%//ToCanonical

%/.CD[a_][A[b_]]->F[a,b]+CD[b][A[a]]

%//ToCanonical

%+temp